/*
 * @Descripttion:
 * @version:
 * @Author: mmzhang
 * @Date: 2021-07-14 14:25:38
 * @LastEditTime: 2022-07-28 10:56:16
 */
import Vue from 'vue'
import config from './config'
config.init(Vue)
import App from './App.vue'
import router from './router'
import store from './store'
import dt from '@dt/dt'
import { Message } from 'view-design'
import '@/assets/icon/iconfont.css'
import { beginAddRouter, routerChecked } from '@/router/routerSlider'
//iview 部分引入
import '@/mixins/iview.js'
import 'view-design/dist/styles/iview.css'

// import { UxGrid, UxTableColumn } from 'umy-ui';
// Vue.use(UxGrid)
// Vue.use(UxTableColumn)
import UmyUi from 'umy-ui'
import 'umy-ui/lib/theme-chalk/index.css' // 引入样式
Vue.use(UmyUi)

import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

import dtComponents from '@/components/dt'
dtComponents.mixin(Vue)

// 组件注册
import '@/common/exportTmp'

// 过滤器
import filters from '@/common/filters'
Vue.prototype.$filters = filters
//全局工具
import secret from '@/common/secretCode.js'
import tool from '@/common/tool'
Vue.prototype.$tool = tool
dt.unlocking = (val) => {
  let buttonControl = JSON.parse(secret.Decrypt(tool.getStorage('buttonControl')))
  if (val) {
    return buttonControl.includes(val)
  }
}
Vue.prototype.unlocking = dt.unlocking

dt.unlockingMenu = (val) => {
  let menuControl = JSON.parse(secret.Decrypt(tool.getStorage('menuControl')))
  if (val) {
    return menuControl.includes(val)
  }
}

Vue.prototype.unlockingMenu = dt.unlockingMenu

//全局常量
import formatter from '@/common/formatter'
Vue.prototype.$formatter = formatter

router.beforeEach((to: any, from: any, next: any) => {
  ;(window as any).onresize = '' // 去除页面window.onresize监听
  if (to.path == '/login') next()
  else if (tool.getStorage('rouList')) {
    // 判断是否需要案场id
    if (to.meta.isbuild == 'buildpage' && !tool.getStorage('caseBuildingId')) {
      ;(Message as any).error('请先选择案场！')
      next('/home')
    } else {
      routerChecked(to)
        .then((res) => {
          next()
        })
        .catch((_) => next('/home'))
    }
  } else next('/login')
})

new Vue({
  router,
  store,
  render: (h) => h(App)
}).$mount('#app')
